package jdbc.date;

import jdbc.mobel.jdlist;
import jdbc.util.BaseDao;

import java.util.List;
import java.util.Scanner;

public class libraryBorrow {//TODO 借书

    static String w1="select * from book where id=2301;";//sql查询语句
    static String w2="select * from book where id=2302;";
    static String w3="select * from book where id=2303;";
    static String w4="select * from book where id=2304;";
    static String w5="select * from book where id=2305;";
    static List<jdlist> work1= BaseDao.executeDQL(w1, jdlist.class);//接收
    static List<jdlist> work2= BaseDao.executeDQL(w2, jdlist.class);
    static List<jdlist> work3= BaseDao.executeDQL(w3, jdlist.class);
    static List<jdlist> work4= BaseDao.executeDQL(w4, jdlist.class);
    static List<jdlist> work5= BaseDao.executeDQL(w5, jdlist.class);
    public static void libraryBorrow(){
        Scanner dr=new Scanner(System.in);
        libraryBorrow s=new libraryBorrow();
        s.let();
        System.out.println("请输入序号选择您想借的书");
        int a=dr.nextInt();

        switch (a){
            case 1:{ String j1="delete from book where id=2301;";
                String j2="insert into book(id,name,math)values (2301,'水浒传',50);";
                int dat= work1.size();//获取目前总数
                BaseDao.executeDML(j1);//先删除所有数据
                for (int i = 0; i <dat-1 ; i++) {//再添加总数减一
                    BaseDao.executeDML(j2);
                }
                System.out.print("本书剩余数量:  ");
                System.out.println(work1.size()-1);
            break;}

            case 2:{String j3="delete from book where id=2302;";
                String j4="insert into book(id,name,math)values(2302,'计算机基础',31);";
                int dat= work2.size();//获取目前总数
                BaseDao.executeDML(j3);//先删除所有数据
                for (int i = 0; i <dat-1 ; i++) {//再添加总数减一
                    BaseDao.executeDML(j4);
                }
                System.out.print("本书剩余数量:  ");
                System.out.println(work2.size()-1);
                break;}

            case 3:{String j5="delete from book where id=2303;";
                String j6="insert into book(id,name,math)values(2303,'数据库原理',35);";
                int dat= work3.size();//获取目前总数
                BaseDao.executeDML(j5);//先删除所有数据
                for (int i = 0; i <dat-1 ; i++) {//再添加总数减一
                    BaseDao.executeDML(j6);
                }
                System.out.print("本书剩余数量:  ");
                System.out.println(work3.size()-1);
                break;}

            case 4:{String j7="delete from book where id=2304;";
                String j8="insert into book(id,name,math)values(2304,'高等数学',42);";
                int dat= work4.size();//获取目前总数
                BaseDao.executeDML(j7);//先删除所有数据
                for (int i = 0; i <dat-1 ; i++) {//再添加总数减一
                    BaseDao.executeDML(j8);
                }
                System.out.print("本书剩余数量:  ");
                System.out.println(work4.size()-1);
                break;}

            case 5:{String j9="delete from book where id=2305;";
                String j0="insert into book(id,name,math)values(2305,'离散数学',51);";
                int dat= work5.size();//获取目前总数
                BaseDao.executeDML(j9);//先删除所有数据
                for (int i = 0; i <dat-1 ; i++) {//再添加总数减一
                    BaseDao.executeDML(j0);
                }
                System.out.print("本书剩余数量:  ");
                System.out.println(work5.size()-1);
                break;}
        }
        System.out.println("借书成功,将为您返回登录页面");
        System.out.println("感谢您的支持,祝您学业有成");
        System.out.println("-----------------------------------------");
        libraryDengLu e=new libraryDengLu();
        e.setDeng();
    }
    public  void let(){
        System.out.println("--------------------------------------");
        System.out.println("现在有以下图书和剩余数量");
        System.out.println("书名      剩余数量");
        System.out.println("1.水浒传: "+work1.size());
        System.out.println("2.计算机基础: "+work2.size());
        System.out.println("3.数据库原理: "+work3.size());
        System.out.println("4.高等数学: "+work4.size());
        System.out.println("5.离散数学: "+work5.size());
    }
}
